FUNCTION_BLOCK LCB_UnitToSpeed
TITLE = 'LCB_UnitToSpeed'
//
// This FB uses the transmitted machine parameters and converts a velocity which
// in the real machine units into a speed and outputs it at dn'SpeedOut_s for further processing in the FB interconnection.
// Versionshistory:
// 1.0 Ersterstellung E.Dittmann

VERSION : '1.0'
AUTHOR  : 'Lenze'
FAMILY  : 'LCB'
NAME : 'UniToSpe'
KNOW_HOW_PROTECT

VAR_INPUT
    AxisData                : BLOCK_DB;                             // 
    rSpeedInUnits           : REAL;                                 // Speed in Units 
END_VAR

VAR_OUTPUT
    diSpeedOut_s            : DINT;                                 // Speed in rpm
    xLimit                  : BOOL;                                 // LimitError   
END_VAR

VAR
    dwTemp                  :DWORD;
    rTemp                   :REAL;
    rSpeedOut_s            :REAL;
END_VAR

        
BEGIN
    dwTemp              :=AxisData.dd76;   // AxisData.rUnitsToSpeed
    rTemp               :=DWORD_TO_REAL(dwTemp);
    rSpeedOut_s         :=rSpeedInUnits *  rTemp;
    IF  (rSpeedOut_s >= 2147483647.0)  THEN
        xLimit := TRUE;
        diSpeedOut_s := 2147483647;
    ELSIF  (rSpeedOut_s <= -2147483647.0) THEN
        xLimit := TRUE;
        diSpeedOut_s := -2147483647;
    ELSE
        xLimit := FALSE;
        diSpeedOut_s := REAL_TO_DINT(rSpeedOut_s);
    END_IF;

END_FUNCTION_BLOCK


